% mysql field types
-define(MYSQL_TYPE_DECIMAL, 0).
-define(MYSQL_TYPE_TINY, 1).
-define(MYSQL_TYPE_SHORT, 2).
-define(MYSQL_TYPE_LONG, 3).
-define(MYSQL_TYPE_FLOAT, 4).
-define(MYSQL_TYPE_DOUBLE, 5).
-define(MYSQL_TYPE_NULL, 6).
-define(MYSQL_TYPE_TIMESTAMP, 7).
-define(MYSQL_TYPE_LONGLONG, 8).
-define(MYSQL_TYPE_INT24, 9).
-define(MYSQL_TYPE_DATE, 10).
-define(MYSQL_TYPE_TIME, 11).
-define(MYSQL_TYPE_DATETIME, 12).
-define(MYSQL_TYPE_YEAR, 13).
-define(MYSQL_TYPE_NEWDATE, 14).
-define(MYSQL_TYPE_VARCHAR, 15).
-define(MYSQL_TYPE_BIT, 16).
-define(MYSQL_TYPE_NEWDECIMAL, 246).
-define(MYSQL_TYPE_ENUM, 247).
-define(MYSQL_TYPE_SET, 248).
-define(MYSQL_TYPE_TINY_BLOB, 249).
-define(MYSQL_TYPE_MEDIUM_BLOB, 250).
-define(MYSQL_TYPE_LONG_BLOB, 251).
-define(MYSQL_TYPE_BLOB, 252).
-define(MYSQL_TYPE_VAR_STRING, 253).
-define(MYSQL_TYPE_STRING, 254).
-define(MYSQL_TYPE_GEOMETRY, 255).

% mysql commands
-define(COM_SLEEP, 16#00). % (none, this is an internal thread state) 
-define(COM_QUIT, 16#01). % mysql_close
-define(COM_INIT_DB, 16#02). % mysql_select_db
-define(COM_QUERY, 16#03). % mysql_real_query
-define(COM_FIELD_LIST, 16#04). % mysql_list_fields
-define(COM_CREATE_DB, 16#05). % mysql_create_db
-define(COM_DROP_DB, 16#06). % mysql_drop_db
-define(COM_REFRESH, 16#07). % mysql_refresh
-define(COM_SHUTDOWN, 16#08). % mysql_shutdown
-define(COM_STATISTICS, 16#09). % mysql_stat 
-define(COM_PROCESS_INFO, 16#0a). % mysql_list_processes 
-define(COM_CONNECT, 16#0b). % (none, this is an internal thread state) 
-define(COM_PROCESS_KILL, 16#0c). % mysql_kill 
-define(COM_DEBUG, 16#0d). % mysql_dump_debug_info 
-define(COM_PING, 16#0e). % mysql_ping 
-define(COM_TIME, 16#0f). % (none, this is an internal thread state) 
-define(COM_DELAYED_INSERT, 16#10). % (none, this is an internal thread state) 
-define(COM_CHANGE_USER, 16#11). % mysql_change_user 
-define(COM_BINLOG_DUMP, 16#12). % sent by the slave IO thread to request a binlog 
-define(COM_TABLE_DUMP, 16#13). % LOAD TABLE ... FROM MASTER (deprecated) 
-define(COM_CONNECT_OUT, 16#14). % (none, this is an internal thread state) 
-define(COM_REGISTER_SLAVE, 16#15). % sent by the slave to register with the master (optional) 
-define(COM_STMT_PREPARE, 16#16). % mysql_stmt_prepare 
-define(COM_STMT_EXECUTE, 16#17). % mysql_stmt_execute 
-define(COM_STMT_SEND_LONG_DATA, 16#18). % mysql_stmt_send_long_data 
-define(COM_STMT_CLOSE, 16#19). % mysql_stmt_close 
-define(COM_STMT_RESET, 16#1a). % mysql_stmt_reset 
-define(COM_SET_OPTION, 16#1b). % mysql_set_server_option 
-define(COM_STMT_FETCH, 16#1c). % mysql_stmt_fetch 

% mysql data types
-define(UINT8, 8/unsigned-little-integer).
-define(UINT16, 16/unsigned-little-integer).
-define(UINT24, 24/unsigned-little-integer).
-define(UINT32, 32/unsigned-little-integer).
-define(UINT48, 48/unsigned-little-integer).
-define(UINT64, 64/unsigned-little-integer).

% mysql client flags
-define(CLIENT_LONG_PASSWORD, 1).        % new more secure passwords
-define(CLIENT_FOUND_ROWS, 2).        % Found instead of affected rows
-define(CLIENT_LONG_FLAG, 4).        % Get all column flags
-define(CLIENT_CONNECT_WITH_DB, 8).        % One can specify db on connect 
-define(CLIENT_NO_SCHEMA, 16).       % Don't allow database.table.column 
-define(CLIENT_COMPRESS, 32).       % Can use compression protocol 
-define(CLIENT_ODBC, 64).       % Odbc client 
-define(CLIENT_LOCAL_FILES, 128).      % Can use LOAD DATA LOCAL 
-define(CLIENT_IGNORE_SPACE, 256).      % Ignore spaces before '(' 
-define(CLIENT_PROTOCOL_41, 512).      % New 4.1 protocol 
-define(CLIENT_INTERACTIVE, 1024).     % This is an interactive client 
-define(CLIENT_SSL, 2048).     % Switch to SSL after handshake 
-define(CLIENT_IGNORE_SIGPIPE, 4096)     % IGNORE sigpipes 
-define(CLIENT_TRANSACTIONS, 8192).     % Client knows about transactions 
-define(CLIENT_RESERVED, 16384).    % Old flag for 4.1 protocol  
-define(CLIENT_SECURE_CONNECTION, 32768).    % New 4.1 authentication 
-define(CLIENT_MULTI_STATEMENTS, 65536).    % Enable/disable multi-stmt support 
-define(CLIENT_MULTI_RESULTS, 131072).   % Enable/disable multi-results

% structure
-record(state, {socket, recvbuf}).
-record(mysql_field, {name, type}).
-record(mysql_result, {metadata, rows}).

% mysql_result
-define(RESULT_OK, 0).
-define(RESULT_ERROR, 255).
-define(RESULT_END, 254).


